<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/base/headcss.jsp"%>
<!DOCTYPE html>
<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>菜单详细</title>
 	<style>
 		.tdname{
 			font-weight:bold;
 			text-align:right;
 		}
 		.center{
 			align:center;
 		}	
 	</style>
	</head>
	<body>
		<div class="center">
			<h3>菜单编辑</h3>
		</div>
		<form id="form1">
	 		 <table class="table  table-bordered table-hover">
			 	    
	 		 		<tr> 
		 		 		<td class="tdname">菜单名称</td>
		 		 		<td><input type="text"  value="${entity.name}" /></td>
		 		 		<td class="tdname">url地址</td>
		 		 		<td><input type="text"  value="${entity.url}" /></td>
	 		 		</tr>  
	 		 		<tr> 
		 		 		<td class="tdname">打开方式</td>
		 		 		<td><input type="text"  value="${entity.openMode}" /></td>
		 		 		<td class="tdname">url地址</td>
		 		 		<td><input type="text"  value="${entity.url}" /></td>
	 		 		</tr>    
	 				<tr> 
		 		 		<td class="tdname">菜单描述</td>
		 		 		<td><input type="text"  value="${entity.description}" /></td>
		 		 		<td class="tdname">图标</td>
		 		 		<td><button class="btn btn-primary" role="iconpicker" data-icon="glyphicon-camera" id="iconButton"></button>
						 <input type="hidden" name="icon"  id="icon" value="${entity.icon}" /></td>
						</td>
	 		 		</tr>    
	 		 		<tr> 
		 		 		<td class="tdname">状态</td>
		 		 		<td><input type="text"  value="${entity.status}" /></td>
		 		 		<td class="tdname">打开状态</td>
		 		 		<td><input type="text"  value="${entity.opened}" /></td>
	 		 		</tr>
	 		 		<tr> 
		 		 		<td class="tdname">资源类别</td>
		 		 		<td colspan="3"><input type="text"  value="${entity.resourceType}" /></td>
	 		 		</tr>  
	 		 </table>
 		 </form>
 		 <div class="center">
 		 		<button class="btn btn-xs btn-primary"
				 onclick="add('${entity.id}','${entity.sort}');">新增</button>
 		        <button class="btn btn-xs btn-info" onclick="save();">
					   保存
				</button>
				<button class="btn btn-xs btn-danger" onclick="deleteResource(${entity.id});">
					删除
				</button>	
				
 		 </div>
	</body> 
    <script type="text/javascript" src="${path}/scripts/jQuery/jquery-1.10.2.min.js" ></script>
	<script type="text/javascript" src="${path}/assets/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="${path}/assets/js/bootstrap-iconpicker-iconset-all.min.js"></script>
	<script type="text/javascript" src="${path}/assets/js/bootstrap-iconpicker.min.js"></script>
     <script type="text/javascript">
	     function save(){
	    	 $.ajax({
 	                //几个参数需要注意一下
 	                type: "POST",//方法类型
 	                dataType: "text",//预期服务器返回的数据类型
 	                url: "<c:url value='/resource/update '/>" ,//url
 	                data: $('#form1').serialize(),
 	                success: function (data) {
 	                    if (data == "success") {
 	                        alert(" 修改成功");
 	                        location.reload();
 	                    }else{
 	                    	alert("修改失败");
 	                    }
 	                },
 	                error : function() {
 	                    alert( " 系统错误 ");
 	                }
	  	      });

	     }
	     function add(pid,sort){
	  	    window.open ("${path}/resource/add?pid="+pid+"&sort="+sort, " 新增菜单", "height=650, width=800, top=200, left=800, toolbar=no"); 
	     }
	     function deleteResource(id){
	  	   if(confirm("是否确认删除菜单 ")){
	  		   $.ajax({
	  	            //几个参数需要注意一下
	  	                type: "GET",//方法类型
	  	                dataType: "text",//预期服务器返回的数据类型
	  	                url: "<c:url value='/resource/delete'/>" ,//url
	  	                data: {'id':id},
	  	                success: function (data) {
	  	                    if (data == "success") {
	  	                        alert("删除成功");
	  	                        location.reload();
	  	                    }else{
	  	                    	alert("删除失败");
	  	                    }
	  	                },
	  	                error : function() {
	  	                    alert("删除失败！");
	  	                }
	  	            });
	  	   }   
	     }
	     $('#iconButton').on('change', function(e) {
	    	   
	    	   $('#icon').val(e.icon);
	    	});
     </script>
</html>